local thbattle__bayiyonglin_tiansi = fk.CreateSkill {

  name = "thbattle__bayiyonglin_tiansi",

  tags = {},

}



thbattle__bayiyonglin_tiansi:addEffect("active", {
  name = "thbattle__bayiyonglin_tiansi",
  prompt = "#thbattle__bayiyonglin_tiansi",
  anim_type = "support",
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and not to_select:isNude()
  end,
  target_num = 1,
  max_phase_use_time = 1,
  on_use = function(self, room, effect)
    local target = effect.tos[1]
    local player = effect.from
    local discard = room:askForCardChosen(player, target, "he", thbattle__bayiyonglin_tiansi.name,"#thbattle__bayiyonglin_tiansi-ask_discard")
    room:throwCard(discard, thbattle__bayiyonglin_tiansi.name, target, player)
    local choice
    local choices = { "回复1点体力", "展示牌堆底3张牌，获得牌堆底的非基本牌" }
    if target:isWounded() then
      choice = room:askForChoice(target, choices, thbattle__bayiyonglin_tiansi.name,
        "#thbattle__bayiyonglin_tiansi-choice")
    else
      choice = choices[2]
    end
    if choice == choices[1] then
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = thbattle__bayiyonglin_tiansi.name,
      })
    else
      local getcards = room:getNCards(3, "bottom")
      room:moveCards({
        ids = getcards,
        toArea = Card.Processing,
        moveReason = fk.ReasonJustMove,
        skillName = thbattle__bayiyonglin_tiansi.name,
        proposer = player
      })
      local removeCid = {}
      for _, cid in ipairs(getcards) do
        if Fk:getCardById(cid).type ~= Card.TypeBasic then
          room:obtainCard(target, cid, true, fk.ReasonPrey, player, thbattle__bayiyonglin_tiansi.name)
          table.insert(removeCid, cid)
        end
      end
      if #removeCid > 0 then
        for _, value in ipairs(removeCid) do
          if table.contains(getcards,value) then
            table.removeOne(getcards,value)
          end
        end
      end
      room:moveCards({
        ids = getcards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonDiscard,
      })
    end
  end,
})

return thbattle__bayiyonglin_tiansi
